﻿using System;
using System.Windows.Input;

namespace fc2editor.Common
{
    public class DelegateCommand<T> : ICommand
    {
        public DelegateCommand(Action<T> action)
        {
            if (action == null)
                throw new NullReferenceException("Illegal null-reference action");

            this.action = action;
        }

        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var arg = (T)parameter;
            action(arg);
        }

        #endregion

        private Action<T> action;
    }
}
